/**
 * Created by OneDream on 2016/1/15.
 */
$(document).ready(function(){

    var oldNickname=localStorage.getItem("nickname");
    $("#text").val(oldNickname);
    var account=localStorage.getItem("account");
    $("#back_img").click(function(){
        history.back();
    });
    $("#rest").click(function(){
        var newNickname=$("#text").val()
        if(newNickname==oldNickname){
            alert("please change your new nickname");
        }else{
            $.ajax({
                url: "http://192.168.1.11:8080/WeiXin/updateNickName",
                data: {
                    "account": account,
                    "nickname":newNickname
                },
                async: true,
                dataType: "json",
                success: function (data) {
                    if (data.status == 0) {
                        localStorage.setItem("nickname",newNickname);
                        alert(data.message);
                        history.back();
                    } else {
                        alert("failure");
                    }
                },
                error: function () {
                    alert("network error");
                }
            });
        }
    });
});